/* GAME */		
	/* AUTO SAVE */
	function autoSave(){
		if(autosave){
			gameSave();
		}
	}
	/* SAVE */
	function gameSave(){
		/* CLICKING */
		localStorage["clicks"] = clicks;
		localStorage["clicks_all_time"] = clicks_all_time;
		localStorage["autoclicking"] = autoclicking;		
		localStorage["autoclickers"] = JSON.stringify(autoclickers);
	
		/* PKMN */
		localStorage["caught"] = caught;
		localStorage["pkmn"] = JSON.stringify(pkmn);
		localStorage["active"] = active;
		localStorage["capturedecrease"] = capturedecrease;
		localStorage["shinychance"] = shinychance;	
		localStorage["clicked_swim_spheal"] = clicked_swim_spheal;
		
		/* ITEMS */	
		localStorage["inventory"] = JSON.stringify(inventory);
		
		/* BERRIES */
		localStorage["berries"] = JSON.stringify(berries);
		
		/* ACHIEVEMENTS */
		localStorage["achievements"] = JSON.stringify(achievements);	
		
		/* UPGRADES */
		localStorage["upgrades"] = JSON.stringify(upgrades);	
			
		/* MISC. */
		localStorage["saved"] = true;
		localStorage["autosave"] = autosave;	
		localStorage["notifs"] = notifs;		
		popUp('游戏已保存!');
	}
	
	/* LOAD */
	function gameLoad(){
		if(localStorage["saved"]){
			/* CLICKING */
			clicks = parseFloat(localStorage["clicks"]);
			clicks_all_time = parseFloat(localStorage["clicks_all_time"]);
			
				/* AUTOCLICKERS */
				var xautoclickers = JSON.parse(localStorage["autoclickers"]);
				var total = xautoclickers.length;
				for (var i = 0; i < total; i++){
					autoclickers[i].quantity = xautoclickers[i].quantity;
					autoclickers[i].amuletcoin = xautoclickers[i].amuletcoin;
					autoclickers[i].cost = Math.round(xautoclickers[i].basecost * Math.pow(1.15,xautoclickers[i].quantity));
				}				
				
			/* PKMN */		
			caught = parseFloat(localStorage["caught"]);
			document.getElementById('caught').innerHTML = numberWithCommas(caught);
			pkmn = JSON.parse(localStorage["pkmn"]);
			active = parseFloat(localStorage["active"]);
			capturedecrease = parseFloat(localStorage["capturedecrease"]);
			shinychance = parseFloat(localStorage["shinychance"]);
			for (var i = 1; i <= caught; i++){
				if (i != pkmn[active].id){
					$('#boxlist').append("<span class='" + pkmn[i].species + "icon' id='" + pkmn[i].id + "' onclick='selectpkmn(this)'></span>");
				}
			}
			clicked_swim_spheal = parseFloat(localStorage["clicked_swim_spheal"]);

			/* ITEMS */
			var xinventory = JSON.parse(localStorage["inventory"]);
			var total = xinventory.length;
			for (var i = 0; i < total; i++){
				inventory[i].quantity = xinventory[i].quantity;
				var item = i;
				for (var n = 0; n < inventory[item].quantity; n++){ 
					$('#inventorylist').append("<span style='cursor: pointer;' onclick='use" + inventory[item].fn + "(this)'><img src='images/items/" + inventory[item].fn + ".png' style='height:24px;width:24px;'/></span>");
				}
			}

			/* BERRIES */
			var xberries = JSON.parse(localStorage["berries"]);
			var total = xberries.length;
			for (var item = 0; item < total; item++){
				berries[item].quantity = xberries[item].quantity;
				for (var n = 0; n < berries[item].quantity; n++){ 
					$('#inventorylist').append("<span style='cursor: pointer;'><img src='images/items/berries/" + berries[item].name + "/img.png' style='height:24px;width:24px;'/></span>");
				}
			}
			
			/* ACHIEVEMENTS */
			var xachievements = JSON.parse(localStorage["achievements"]);
			var total = xachievements.length;
			for (var i = 0; i < total; i++){
				achievements[i].achieved = xachievements[i].achieved;
			}
			/* UPGRADES */
			if (localStorage.getItem("upgrades") !== null) {
				var xupgrades = JSON.parse(localStorage["upgrades"]);
				var total = xupgrades.length;
				for (var i = 0; i < total; i++){
					upgrades[i].unlocked = xupgrades[i].unlocked;
					upgrades[i].purchased = xupgrades[i].purchased;
				}
			}	
			
			/* MISC. */
			withdrawn = true;
			calcmodifier();
			autosave = localStorage["autosave"];
			notifs = localStorage["notifs"];
			withdrawpkmn(pkmn[active].id);
			
			popUp('游戏已加载!');
			
		}else{
			capturepkmn(1,false);
			active = 1;
			localStorage["active"] = active;
			withdrawpkmn(pkmn[1].id);
		}
		upgrade_effects();
		appendclickers();
		append_upgrades();
		appendachievements();
		recalccps();
		updateTitle();
	}
	
	/* CLEAR */
	function gameClear(){	
		/* CLICKING */
		delete window.localStorage["clicks"];
		delete window.localStorage["clicks_all_time"];
		delete window.localStorage["cps"];
		delete window.localStorage["autoclickers"];
		
		/* PKMN */
		delete window.localStorage["caught"];
		delete window.localStorage["pkmn"];
		delete window.localStorage["active"];
		delete window.localStorage["capturedecrease"];
		delete window.localStorage["shinychance"];

		/* ITEMS */
		delete window.localStorage["inventory"];

		/* BERRIES */
		delete window.localStorage["berries"];
		
		/* ACHIEVEMENTS */
		delete window.localStorage["achievements"];
		
		/* UPGRADES */
		delete window.localStorage["upgrades"];		
		
		/* MISC. */
		delete window.localStorage["autosave"];
		delete window.localStorage["notifs"];		
		delete window.localStorage["saved"];
		
		popUp('游戏存档已清理');
		location.reload();
	}
